package mylib.archive.y2012.m08.SNSS_R3;

import mylib.dir.ArrayUtils;
import mylib.dir.FastInputReader;
import mylib.dir.InputUtils;

import java.io.PrintWriter;

public class taskE {
    public void solve(int testNumber, FastInputReader in, PrintWriter out) {
        int n = in.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        InputUtils.inputArray(in, a, b);
        ArrayUtils.addToArray(a, -1);
        ArrayUtils.addToArray(b, -1);
        long[][][] count = new long[1 << n][7][7];
        boolean[][] set = new boolean[7][7];
        for (int i = 0; i < n; ++i) {
            int ta = a[i], tb = b[i];
            {
                if (!set[ta][tb]) {
                    count[1 << i][ta][tb]++;
                    set[ta][tb] = true;
                }
            }
            ta = b[i];
            tb = a[i];
            {
                if (!set[ta][tb]) {
                    count[1 << i][ta][tb]++;
                    set[ta][tb] = true;
                }
            }
        }
        for (int mask = 0; mask < (1 << n); ++mask)
            for (int first = 0; first < 7; ++first)
                for (int last = 0; last < 7; ++last) {
                    if (count[mask][first][last] == 0)
                        continue;
                    boolean[][] set1 = new boolean[7][7];
                    for (int i = 0; i < n; ++i) {
                        if (((mask >> i) & 1) != 0)
                            continue;
                        int ta = a[i], tb = b[i];
                        {
                            if (!set1[ta][tb] && last == ta) {
                                count[mask + (1 << i)][first][tb] += count[mask][first][last];
                                set1[ta][tb] = true;
                            }
                        }
                        ta = b[i];
                        tb = a[i];
                        {
                            if (!set1[ta][tb] && last == ta) {
                                count[mask + (1 << i)][first][tb] += count[mask][first][last];
                                set1[ta][tb] = true;
                            }
                        }
                    }

                }
        long ans = 0;
        for (int i = 0; i < 7; ++i) {
            ans += count[(1 << n) - 1][i][i];
        }
        out.print(ans);
    }
}
